package com.t235.gc.biz.service;

import com.t235.gc.AjaxResult;
import com.t235.gc.bizvo.SortingListVo;
import com.t235.gc.entity.FinanceSorting;
import com.t235.gc.entity.SysManager;
import com.t235.gc.mapper.FinanceSortingMapper;
import com.t235.gc.mapper.SysManagerMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * @Description :
 * Created by Li on 2021-04-09 11:41:22
 */
@Service
public class SortingService {
    @Autowired
    private SysManagerMapper sysManagerMapper;
    @Autowired
    private FinanceSortingMapper financeSortingMapper;

    public List<SortingListVo> getManagerList(SysManager sysManager) {
        return sysManagerMapper.selectByParam(sysManager);
    }

    public String insertSelective(SysManager sysManager) {
        int i = sysManagerMapper.insertSelective(sysManager);
        if(i>0) {
            return "success";
        } else {
            return "error";
        }
    }

    public String updateByPrimaryKeySelective(SysManager sysManager) {
        int i = sysManagerMapper.updateByPrimaryKeySelective(sysManager);
        if(i>0) {
            return "success";
        } else {
            return "error";
        }
    }

    public String delManager(String managerid) {
        int i = sysManagerMapper.deleteByPrimaryKey(managerid);
        if(i>0) {
            return "success";
        } else {
            return "error";
        }
    }

    public String addFinanceSorting(FinanceSorting financeSorting) {
        financeSorting.setBalance( financeSortingMapper.selectBalanceById(financeSorting.getManagerid()));
        if(financeSorting.getFinancetype()==5) {
            financeSorting.setBalance(financeSorting.getBalance()+financeSorting.getFee());
        } else {
            financeSorting.setBalance(financeSorting.getBalance()-financeSorting.getFee());
        }
        String id = Math.random() * 0.99 + "";
        id = id.substring(id.indexOf(".") + 1, 18);
        financeSorting.setFinanceid(Long.parseLong(id));
        financeSorting.setCtime(new Date());
        int i = financeSortingMapper.insertSelective(financeSorting);
        if(i>0) {
            return "success";
        } else {
            return "error";
        }
    }
}
